#pragma once
#include <iostream>
#include <string>
#include<ctemplate/template.h>
// #include"oj_model.hpp"
#include "oj_model2.hpp"
namespace ns_view
{
    using namespace std;
    using namespace ns_model;
    const std::string template_path="./template_html/";
    class View
    { 


        public:
        View()
        {

        }
        ~View()
        {

        }
        void AllExpandHtml(const vector<struct Question> &questions,string *html)
        {
            //题目的编号
            //题目的标题 难度
            const string src_html=template_path+"all_questions.html";
            ctemplate::TemplateDictionary root("all_questions");
            for(const auto&q:questions)
            {
                ctemplate::TemplateDictionary *sub=root.AddSectionDictionary("questions_list");
                sub->SetValue("number",q.number);
                sub->SetValue("title",q.title);
                sub->SetValue("star",q.star);
            }
            //3.获取被渲染的html
            ctemplate::Template *tpl=ctemplate::Template::GetTemplate(src_html,ctemplate::DO_NOT_STRIP);
            tpl->Expand(html,&root);
        }
        void OneExpandHtml(const struct Question &q,string *html)
        {
            string src_html=template_path+"one_question.html";
            ctemplate::TemplateDictionary root("one_question");
            std::cout<<q.title.c_str()<<"\n";
            root.SetValue("number",q.number);
            root.SetValue("title",q.title);
            root.SetValue("star",q.star);
            root.SetValue("desc",q.desc);
            root.SetValue("pre_code",q.header);
            ctemplate::Template *tpl=ctemplate::Template::GetTemplate(src_html,ctemplate::DO_NOT_STRIP);
            tpl->Expand(html,&root);
        }


    };



}